name: Python Unit Tests

on:
  pull_request:
    branches: ["main", "feature*"]
    paths:
      - "python/**"

jobs:
  python-unit-tests:
    name: Python Unit Tests
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.10", "3.11", "3.12"]
        os: [ubuntu-latest, windows-latest, macos-latest]
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
      - name: Install poetry
        run: pipx install poetry
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: "poetry"
      - name: Install dependencies
        run: cd python && poetry install --with unit-tests
      - name: Test with pytest
        run: cd python && poetry run pytest -q --junitxml=pytest-${{ matrix.os }}-${{ matrix.python-version }}.xml  --cov=semantic_kernel --cov-report=term-missing:skip-covered ./tests/unit | tee python-coverage-${{ matrix.os }}-${{ matrix.python-version }}.txt
      - name: Upload coverage
        uses: actions/upload-artifact@v4
        with:
          name: python-coverage-${{ matrix.os }}-${{ matrix.python-version }}.txt
          path: python/python-coverage-${{ matrix.os }}-${{ matrix.python-version }}.txt
          overwrite: true
          retention-days: 1  
      - name: Upload pytest.xml
        uses: actions/upload-artifact@v4
        with:
          name: pytest-${{ matrix.os }}-${{ matrix.python-version }}.xml
          path: python/pytest-${{ matrix.os }}-${{ matrix.python-version }}.xml
          overwrite: true
          retention-days: 1
